/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package src.view.saving;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.primefaces.event.CloseEvent;
import org.primefaces.event.SelectEvent;
import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortOrder;
import src.domain.saving.Saving;
import src.services.CRUEDService;

/**
 *
 * @author jasuke
 */
@ManagedBean
@SessionScoped
public final class SearchSavingBean implements Serializable{

    /**
     * Creates a new instance of SearchCustomer
     */
      //  private int pageSize = 5;
    private LazyDataModel<Saving> lazyModel;  
    private Saving selectedData;  
    private String cif, nama, norek;
    private boolean showLookup=false;
    private Short savStatus = 0;
        
    public SearchSavingBean() {
        selectedData = null;
        cif = null;
        nama = null;
        norek = null;
        showLookup=false;
    }

    public boolean isShowLookup() {
        return showLookup;
    }

    public void setShowLookup(boolean showLookup) {
        this.showLookup = showLookup;
    }
        
    public Saving getSelectedData() {
        return selectedData;
    }

    public void setSelectedData(Saving selectedData) {
        this.selectedData = selectedData;
    }

    public String getCif() {
        return cif;
    }

    public void setCif(String cif) {
        this.cif = cif;
    }

    public String getNama() {
        return nama;
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

    public String getNorek() {
        return norek;
    }

    public void setNorek(String norek) {
        this.norek = norek;
    }
        
    public void handleClose(CloseEvent event) {
        this.showLookup=false;
    }
    
    public void loadData() {
        lazyModel = new LazyDataModel<Saving>() {

            @Override
            public List<Saving> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String,String> filters) { 
                int start = first;
                int end = first + pageSize;

                if (savStatus == null) savStatus = 0;
                 
                filters.put("customer.cif", cif);
                filters.put("customer.customerName", nama);
                filters.put("closeDate", "null");
                filters.put("closedBy", "null");
                filters.put("approvalUid", "notnull");
                if (savStatus > 0) filters.put("savStatus", savStatus.toString());

                List<Saving> list = (List) new CRUEDService().loadLazy("Saving", start, end, sortField, sortOrder, filters);
                
                Integer count = new CRUEDService().countLazy("Saving", filters);
                lazyModel.setRowCount(count);
                return list;
            }
        };
    }
                        
    public void onRowSelected(SelectEvent selectEvent) {}
    
    public LazyDataModel<Saving> getLazyModel () {
        return lazyModel;
    }

    public Short getSavStatus() {
        return savStatus;
    }

    public void setSavStatus(Short savStatus) {
        this.savStatus = savStatus;
    }
    
    
    
   
}
